package com.wzl.service.impl;

import com.wzl.common.PubException;
import com.wzl.common.errcode.ErrorCodeEnum;
import com.wzl.common.pojo.UserPojo;
import com.wzl.mapper.MpBasicUsageMapper;
import com.wzl.service.MpBasicUsageService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * Mp基本操作接口实现类
 *
 * @author weizhongli
 * @since 2022-09-10 16:11
 */
@Service
public class MpBasicUsageServiceImpl implements MpBasicUsageService {

    @Resource
    private MpBasicUsageMapper mpBasicUsageMapper;

    @Override
    @Transactional(rollbackFor = PubException.class)
    public UserPojo getUserById(Integer id) {
        try {
            return mpBasicUsageMapper.selectById(id);
        } catch (Exception e) {
            throw new PubException(ErrorCodeEnum.GET_BY_ID_ERROR);
        }
    }

    @Override
    @Transactional(rollbackFor = PubException.class)
    public int UpdateUserById(Integer id) {
        UserPojo userPojo = new UserPojo();
        userPojo.setName("哈哈哈");
        try {
            return mpBasicUsageMapper.updateById(userPojo);
        } catch (Exception e) {
            throw new PubException(ErrorCodeEnum.UPDATE_BY_ID_ERROR);
        }
    }

    @Override
    @Transactional(rollbackFor = PubException.class)
    public int InsertUserById() {
        UserPojo userPojo = new UserPojo();
        userPojo.setId(1000001);
        userPojo.setName("测试插入");
//        userPojo.setPassword(123451);
        try {
            return mpBasicUsageMapper.insert(userPojo);
        } catch (Exception e) {
            throw new PubException(ErrorCodeEnum.INSERT_ERROR);
        }
    }
}